#include "aidialogboxwid.h"
#include "ui_aidialogboxwid.h"

#include <QMovie>

AIDialogBoxWid::AIDialogBoxWid(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::AIDialogBoxWid)
{
    ui->setupUi(this);
    QMovie *movie = new QMovie(":/img/qrc/img/aiHead.gif");
    ui->label->setMovie(movie); // 1. 设置要显示的 GIF 动画图片
    ui->label->setScaledContents(true);
    movie->start();         // 2. 启动动画
}

AIDialogBoxWid::~AIDialogBoxWid()
{
    delete ui;
}

void AIDialogBoxWid::setText(const QString &text)
{
    ui->textBrowser->setMarkdown(text);
    // 动态调整高度
    int newHeight = ui->textBrowser->document()->size().rheight();
    if (newHeight != ui->textBrowser->height()) {
        ui->textBrowser->setFixedHeight(newHeight);
    }
    emit sig_size_hint(newHeight);
}

QSize AIDialogBoxWid::sizeHint() const
{
    return QSize(100, ui->textBrowser->height() + 20);
}

void AIDialogBoxWid::resizeEvent(QResizeEvent *event)
{
    // 动态调整高度
    int newHeight = ui->textBrowser->document()->size().rheight();
    if (newHeight != ui->textBrowser->height()) {
        ui->textBrowser->setFixedHeight(newHeight);
    }
    emit sig_size_hint(newHeight);
}
